package com.v2.activity;

import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.text.TextUtils;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.v2.request.RequestCenter;
import com.v2.utils.TToast;
import com.zou.lotterylucky.R;
import com.zou.lotterylucky.adapters.WinningLotteryAdapter;
import com.zou.lotterylucky.data.WinningLottery;
import com.zou.lotterylucky.databinding.ActivityWinLotterBinding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;

public class WinLotteryActivity extends BaseActivity<ActivityWinLotterBinding> {

    private Calendar calendar = Calendar.getInstance();
    private LinearLayoutManager linearLayoutManager;
    private List<WinningLottery> winningLotteryList = new ArrayList<>();
    private WinningLotteryAdapter adapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_win_lotter;
    }

    @Override
    protected void onCreate() {
        mBinding.topbar.setTitle(R.string.winning_numbers);
        mBinding.topbar.addLeftBackImageButton().setOnClickListener(v -> onBackPressed());

        DatePickerDialog.OnDateSetListener dateSetListener = (view, year, month, dayOfMonth) -> {
            calendar.set(Calendar.YEAR, year);
            calendar.set(Calendar.MONTH, month);
            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            updateDateView();
        };

        mBinding.dateTxt.setOnClickListener(v -> {
            new DatePickerDialog(this, dateSetListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();
        });

        mBinding.searchBtn.setOnClickListener(v -> {
            if (TextUtils.isEmpty(mBinding.dateTxt.getText().toString())) {
                TToast.show(R.string.input_date);
                return;
            }

            //RequestCenter.getWinningHistoryByDateRange(null);
        });

        updateDateView();

        linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        mBinding.numberListView.setLayoutManager(linearLayoutManager);
        adapter = new WinningLotteryAdapter(winningLotteryList);
        mBinding.numberListView.setAdapter(adapter);

        loadWinningNumbers();
    }

    private void loadWinningNumbers() {

    }

    @SuppressLint("SimpleDateFormat")
    private void updateDateView() {
        String format = "yyyy-MM-dd";
        SimpleDateFormat dateFormat = new SimpleDateFormat(format, Locale.US);
        mBinding.dateTxt.setText(dateFormat.format(calendar.getTime()));
    }
}
